<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>BFC</title>
    <style>
        .box {
            border: 1px solid;
        }

        .box1 {
            margin-bottom: 20px;
            width: 100px;
            height: 100px;
            background-color: red;
        }

        .box2 {
            margin-top: 50px;
            width: 100px;
            height: 100px;
            background-color: orange;
        }

        .box3 {
            height: 200px;
            width: 200px;
            background-color: orange;
        }

        .box4 {
            width: 200px;
            height: 200px;
            background-color: red;
            border: 1px solid black;
            float: left;
        }

        .box5 {
            width: 400px;
            height: 400px;
            background-color: orange;
        }
    </style>
</head>

<body>
    <!-- 1.利用BFC避免外边距塌陷。 -->
    <div class="box3">
        <div class="box1"></div>
    </div>
    <hr>


    <!-- 2.利用BFC避免外边距重叠。 -->
    <div class="box">
        <div style="overflow: hidden;">
            <div class="box1"></div>
        </div>
        <div class="box2"></div>
    </div>


    <!-- 3.BFC不会与浮动元素重叠 -->
    <hr>
    <div class="box4"></div>
    <div class="box5"></div>


    <!-- 4.清除浮动 -->
    <hr>
    <div class="box">
        <div class="box4"></div>
        <div class="box4"></div>
        <div class="box4"></div>
        <div class="box4"></div>
    </div>
    <div class="box5"></div>

    <hr>
    <div class="box">
        <img src="https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3363295869,2467511306&fm=26&gp=0.jpg"
            alt="">
    </div>
</body>

</html>